<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">

      <el-form-item label="配置名称" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入配置项名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['wisdom:scene:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['wisdom:scene:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['wisdom:scene:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['wisdom:scene:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="sceneList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="场景ID" align="center" prop="id" />
      <el-table-column label="配置名称" align="center" prop="name" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['wisdom:scene:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['wisdom:scene:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改场景管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="${comment}" prop="comId">
          <el-input v-model="form.comId" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="配置项名称" prop="name">
          <el-input v-model="form.name" placeholder="请输入配置项名称" />
        </el-form-item>
        <el-form-item label="关联设备" prop="deviceNo">
          <el-input v-model="form.deviceNo" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="到校通知老师 0不通知 1 通知" prop="comeSendTeacher">
          <el-input v-model="form.comeSendTeacher" placeholder="请输入到校通知老师 0不通知 1 通知" />
        </el-form-item>
        <el-form-item label="到校通知监护人 0不通知 1 通知" prop="comeSendParent">
          <el-input v-model="form.comeSendParent" placeholder="请输入到校通知监护人 0不通知 1 通知" />
        </el-form-item>
        <el-form-item label="离校通知老师 0不通知 1 通知" prop="leaveSendTeacher">
          <el-input v-model="form.leaveSendTeacher" placeholder="请输入离校通知老师 0不通知 1 通知" />
        </el-form-item>
        <el-form-item label="离校通知监护人 0不通知 1 通知" prop="leaveSendParent">
          <el-input v-model="form.leaveSendParent" placeholder="请输入离校通知监护人 0不通知 1 通知" />
        </el-form-item>
        <el-form-item label="超时不离校通知老师  0不通知 1 通知" prop="overtimeLeaveTeacher">
          <el-input v-model="form.overtimeLeaveTeacher" placeholder="请输入超时不离校通知老师  0不通知 1 通知" />
        </el-form-item>
        <el-form-item label="超时不离校通知监护人  0不通知 1 通知" prop="overtimeLeaveParent">
          <el-input v-model="form.overtimeLeaveParent" placeholder="请输入超时不离校通知监护人  0不通知 1 通知" />
        </el-form-item>
        <el-form-item label="超过当前时间不离校 HH:ii:mm" prop="overtimeLeaveTime">
          <el-input v-model="form.overtimeLeaveTime" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="超时进校 HH:ii:mm" prop="overtimeComeTime">
          <el-input v-model="form.overtimeComeTime" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="超时不进校通知老师  0不通知 1 通知" prop="overtimeComeTeacher">
          <el-input v-model="form.overtimeComeTeacher" placeholder="请输入超时不进校通知老师  0不通知 1 通知" />
        </el-form-item>
        <el-form-item label="超时不进校通知监护人  0不通知 1 通知" prop="overtimeComeParent">
          <el-input v-model="form.overtimeComeParent" placeholder="请输入超时不进校通知监护人  0不通知 1 通知" />
        </el-form-item>
        <el-form-item label="超时未到校提醒" prop="overtimeNocomeTime">
          <el-input v-model="form.overtimeNocomeTime" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="超时未到校提醒监护人  0不通知 1 通知" prop="overtimeNocomeParent">
          <el-input v-model="form.overtimeNocomeParent" placeholder="请输入超时未到校提醒监护人  0不通知 1 通知" />
        </el-form-item>
        <el-form-item label="超时未到校通知老师  0不通知 1 通知" prop="overtimeNocomeTeacher">
          <el-input v-model="form.overtimeNocomeTeacher" placeholder="请输入超时未到校通知老师  0不通知 1 通知" />
        </el-form-item>
        <el-form-item label="体温异常通知家长" prop="temperatureParent">
          <el-input v-model="form.temperatureParent" placeholder="请输入体温异常通知家长" />
        </el-form-item>
        <el-form-item label="体温异常通知老师" prop="temperatureTeacher">
          <el-input v-model="form.temperatureTeacher" placeholder="请输入体温异常通知老师" />
        </el-form-item>
        <el-form-item label="进校时间段" prop="comeTime">
          <el-input v-model="form.comeTime" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="出校时间段" prop="outTime">
          <el-input v-model="form.outTime" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="临时放行提示" prop="releaseTip">
          <el-input v-model="form.releaseTip" placeholder="请输入临时放行提示" />
        </el-form-item>
        <el-form-item label="临时放行提示" prop="releaseLength">
          <el-input v-model="form.releaseLength" placeholder="请输入临时放行提示" />
        </el-form-item>
        <el-form-item label="家长到校播报设备" prop="broadcastDevice">
          <el-input v-model="form.broadcastDevice" placeholder="请输入家长到校播报设备" />
        </el-form-item>
        <el-form-item label="接收总会的老师，逗号隔开" prop="receiveTeacher">
          <el-input v-model="form.receiveTeacher" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="是否启动考勤" prop="isAttendance">
          <el-input v-model="form.isAttendance" placeholder="请输入是否启动考勤" />
        </el-form-item>
        <el-form-item label="是否测温" prop="isTemperature">
          <el-input v-model="form.isTemperature" placeholder="请输入是否测温" />
        </el-form-item>
        <el-form-item label="异常体温" prop="temperatureMax">
          <el-input v-model="form.temperatureMax" placeholder="请输入异常体温" />
        </el-form-item>
        <el-form-item label="播报体温" prop="broadcastTemperature">
          <el-input v-model="form.broadcastTemperature" placeholder="请输入播报体温" />
        </el-form-item>
        <el-form-item label="同步状态 1已同步 0未同步" prop="syn">
          <el-input v-model="form.syn" placeholder="请输入同步状态 1已同步 0未同步" />
        </el-form-item>
        <el-form-item label="是否运行家属通行 0不运行 1运行" prop="allowPassParent">
          <el-input v-model="form.allowPassParent" placeholder="请输入是否运行家属通行 0不运行 1运行" />
        </el-form-item>
        <el-form-item label="考勤对象 1老师，2学生 " prop="attendanceObject">
          <el-input v-model="form.attendanceObject" placeholder="请输入考勤对象 1老师，2学生 " />
        </el-form-item>
        <el-form-item label="其他配置项" prop="options">
          <el-input v-model="form.options" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listScene, getScene, delScene, addScene, updateScene } from "@/api/wisdom/scene";

export default {
  name: "Scene",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 场景管理表格数据
      sceneList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        comId: null,
        name: null,
        deviceNo: null,
        comeSendTeacher: null,
        comeSendParent: null,
        leaveSendTeacher: null,
        leaveSendParent: null,
        overtimeLeaveTeacher: null,
        overtimeLeaveParent: null,
        overtimeLeaveTime: null,
        overtimeComeTime: null,
        overtimeComeTeacher: null,
        overtimeComeParent: null,
        overtimeNocomeTime: null,
        overtimeNocomeParent: null,
        overtimeNocomeTeacher: null,
        temperatureParent: null,
        temperatureTeacher: null,
        comeTime: null,
        outTime: null,
        releaseTip: null,
        releaseLength: null,
        broadcastDevice: null,
        type: null,
        receiveTeacher: null,
        isAttendance: null,
        isTemperature: null,
        temperatureMax: null,
        broadcastTemperature: null,
        status: null,
        syn: null,
        allowPassParent: null,
        attendanceObject: null,
        options: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        comId: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        comeSendTeacher: [
          { required: true, message: "到校通知老师 0不通知 1 通知不能为空", trigger: "blur" }
        ],
        comeSendParent: [
          { required: true, message: "到校通知监护人 0不通知 1 通知不能为空", trigger: "blur" }
        ],
        leaveSendTeacher: [
          { required: true, message: "离校通知老师 0不通知 1 通知不能为空", trigger: "blur" }
        ],
        leaveSendParent: [
          { required: true, message: "离校通知监护人 0不通知 1 通知不能为空", trigger: "blur" }
        ],
        overtimeLeaveTeacher: [
          { required: true, message: "超时不离校通知老师  0不通知 1 通知不能为空", trigger: "blur" }
        ],
        overtimeLeaveParent: [
          { required: true, message: "超时不离校通知监护人  0不通知 1 通知不能为空", trigger: "blur" }
        ],
        overtimeComeTeacher: [
          { required: true, message: "超时不进校通知老师  0不通知 1 通知不能为空", trigger: "blur" }
        ],
        overtimeComeParent: [
          { required: true, message: "超时不进校通知监护人  0不通知 1 通知不能为空", trigger: "blur" }
        ],
        overtimeNocomeParent: [
          { required: true, message: "超时未到校提醒监护人  0不通知 1 通知不能为空", trigger: "blur" }
        ],
        overtimeNocomeTeacher: [
          { required: true, message: "超时未到校通知老师  0不通知 1 通知不能为空", trigger: "blur" }
        ],
        temperatureParent: [
          { required: true, message: "体温异常通知家长不能为空", trigger: "blur" }
        ],
        temperatureTeacher: [
          { required: true, message: "体温异常通知老师不能为空", trigger: "blur" }
        ],
        releaseLength: [
          { required: true, message: "临时放行提示不能为空", trigger: "blur" }
        ],
        type: [
          { required: true, message: "应用场景 1 出入校门 2出入宿舍 3校门进出通用不能为空", trigger: "change" }
        ],
        isAttendance: [
          { required: true, message: "是否启动考勤不能为空", trigger: "blur" }
        ],
        isTemperature: [
          { required: true, message: "是否测温不能为空", trigger: "blur" }
        ],
        status: [
          { required: true, message: "状态1 正常 0删除不能为空", trigger: "change" }
        ],
        allowPassParent: [
          { required: true, message: "是否运行家属通行 0不运行 1运行不能为空", trigger: "blur" }
        ],
        createTime: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        updateTime: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询场景管理列表 */
    getList() {
      this.loading = true;
      listScene(this.queryParams).then(response => {
        this.sceneList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        comId: null,
        name: null,
        deviceNo: null,
        comeSendTeacher: null,
        comeSendParent: null,
        leaveSendTeacher: null,
        leaveSendParent: null,
        overtimeLeaveTeacher: null,
        overtimeLeaveParent: null,
        overtimeLeaveTime: null,
        overtimeComeTime: null,
        overtimeComeTeacher: null,
        overtimeComeParent: null,
        overtimeNocomeTime: null,
        overtimeNocomeParent: null,
        overtimeNocomeTeacher: null,
        temperatureParent: null,
        temperatureTeacher: null,
        comeTime: null,
        outTime: null,
        releaseTip: null,
        releaseLength: null,
        broadcastDevice: null,
        type: null,
        receiveTeacher: null,
        isAttendance: null,
        isTemperature: null,
        temperatureMax: null,
        broadcastTemperature: null,
        status: null,
        syn: null,
        allowPassParent: null,
        attendanceObject: null,
        options: null,
        createTime: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加场景管理";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getScene(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改场景管理";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateScene(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addScene(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除场景管理编号为"' + ids + '"的数据项？').then(function() {
        return delScene(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('wisdom/scene/export', {
        ...this.queryParams
      }, `scene_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
